class Solution:
    def matrixScore(self, A) -> int:
        width=len(A[0])
        height=len(A)
        def reverseRow(x):
            for i in range(width):
                A[x][i]=(A[x][i]-1)*-1
        def reverseCol(y):
            for i in range(height):
                A[i][y]=(A[i][y]-1)*-1
        def calcCol(y):
            res=0
            for i in range(height):
                res+=A[i][y]
            return res
        for i in range(height):
            if A[i][0]==0:
                reverseRow(i)
        for i in range(1,width):
            if calcCol(i)<=height//2:
                reverseCol(i)
        result=0
        for i in range(width):
            for j in range(height):
                if A[j][i]==1:
                    result+=A[j][i]*(2**(width-1-i))
        return result
s=Solution()
print(s.matrixScore([[0,0,1,1],[1,0,1,0],[1,1,0,0]]))


'''
执行用时：
48 ms
, 在所有 Python3 提交中击败了
69.62%
的用户
内存消耗：
13.6 MB
, 在所有 Python3 提交中击败了
15.38%
的用户
'''
